def pr_number(n):
  if n <= 1:
    return False
  for i in range(2, int(n*0.5) + 1):
    if n % i == 0:
      return False
  return True

def ptr_number(number):
  if number <= 1000 or number >=  9999:
    return 0
  digits = str(number)
  max_p = 0
  for i in range(4):
    for j in range(i + 1, 5):
      num_str = digits[i:j]
      num = int(num_str.lstrip("0")) 
      if pr_number(num) and num > max_p:
        max_p = num
  return max_p

number = int(input())
print(ptr_number(number))
